import request from './request'

const http={
    // get请求
    get(url,param){
        let urlParams = []
        if(param){
            for(let key in param){
                urlParams.push(key + "=" + param[key])
            }
            if(urlParams.length>0){
                url += "?" + urlParams.join("&")
            }
        }
        return request({
            url:url,
            method:'get',
        })
    },
    // post请求
    post(url,data){
        return request({
            url:url,
            method:'post',
            data:data,
            // 请求头可以按照需求自己改变
            headers:{
                // 'Content-Type':'application/x-www-form-urlencoded;charset=utf-8'
                // java服务端需要@RequestBody解析,node.js网上查了,就说bodyParser.json()就行,但是我没成功(后面成功了,是后端跨域那里没做好)
                'Content-Type':'application/json'
            }
        })
    },
    // delete请求
    delete(url){
        return request({
            url:url,
            method:'delete',
        })
    },
    // put请求
    put(url,data){
        return request({
            url:url,
            method:'put',
            data:data,
            headers:{
                'Content-Type':'application/json'
            }
        })
    },
}

export default http